feat(sdk)!: Use StreamrClientError
instead of StreamMessagError
#2927
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a breaking change
Use
StreamrClientError
instead ofStreamMessageError
:streamMessage
parameter toStreamrClientErrorCode
InvalidJsonError
removed, usingINVALID_MESSAGE_CONTENT
error code insteadINVALID_SIGNATURE
INVALID_PARTITION
ASSERTION_FAILED
StreamMessage
object, we can assume thatStreamMessage
instance has a valid value for themessageType
property as all instances are created by our internalStreamMessageTranslator
utility. We have aswitch
statement for handling different message types, and there we can throw an error withASSERTION_FAILED
code ifmessageType
is not any of the valid message types.MISSING_PERMISSION
error codeRemoved
StreamMessageError
class.The
StreamrClientError
class has an optional constructor parameter for specifying relatedStreamMessage
. When that is used, the error message contains a string representation of theMessageID
. TheMessageID
is also stored to the error object as a field to make it accessible programmatically.StreamMessagError
stored the wholeStreamMessage
object. Therefore e.g. the whole message content was exposed if the error was logged. This change resolves issue NET-1378.Also
code
is now included in the error message. It is good to duplicate thecode
andmessageId
info in the error message as custom error fields are not shown e.g. in browser environment outputs.Output in logs
In the NodeJS an error is written to the output like this:
In browser environments an error is written to the output like this:
Note that e.g. in NodeJS logs the
messageId
info is duplicated. In some other environments only the error message is visible, it is good to have the info also in the message.Open questions
Maybe this is not a breaking changes as we've not documented our errors? I.e. this is functionality change but but an API change.
Note
The change implemented in 6c5f4fcc6 is maybe not needed at all? Should improve test coverage and maybe remove the
ignoreMessages
functionality (if theonError
is never called with theStreamMessage
parameter?)Future improvements
ValidationError
and useStreamrClientError
instead of thatnew Error('streamId required')
) withStreamrClientError